package com.qf.service.impl;

import com.qf.dao.TrainTicketMapper;
import com.qf.dao.repository.TrainTicketRepository;
import com.qf.pojo.po.TrainTicket;
import com.qf.pojo.resp.BaseResp;
import com.qf.service.TrainTicketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;
import java.util.concurrent.locks.Lock;

/**
 * @author lipengg
 * @date 2021/10/25
 */
@Service
public class TrainTicketServiceImpl implements TrainTicketService {

    @Autowired
    private TrainTicketMapper trainTicketMapper;

    @Autowired
    private TrainTicketRepository trainTicketRepository;

    @Override
    public  BaseResp isByTicket() {
        synchronized (this){
            Optional<TrainTicket> byId = trainTicketRepository.findById(1);
            TrainTicket trainTicket = byId.get();
            System.out.println("当前票数:"+trainTicket.getDTicketNum());
            trainTicket.setDTicketNum(trainTicket.getDTicketNum()-1);
            trainTicketMapper.updateTicketNum(trainTicket);
            return null;
        }

    }
}
